/**
 * 
 */
package com.yst.metho.web.application.rights.actions;

import java.util.ArrayList;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;

import nextapp.echo2.app.Extent;
import nextapp.echo2.app.event.ActionEvent;

import com.yst.metho.web.application.SuiviProdApp;
import com.yst.metho.web.application.components.GenericEditWindow;
import com.yst.metho.web.application.components.listingview.ToolbarAction;
import com.yst.metho.web.application.rights.RightsListModel;
import com.yst.metho.web.application.rights.RightsPane;
import com.yst.metho.web.application.utils.ExceptionMgt;
import com.yst.metho.web.application.utils.Locator;
import com.yst.suivi.data.rights.Right;

/**
 * @author perso
 * 
 */
public class CreateProfil extends ToolbarAction
{
	protected static final Extent POPUP_HEIGHT = new Extent(400, Extent.PX);
	protected static final Extent POPUP_WIDTH = new Extent(400, Extent.PX);

	private RightsListModel mModel;

	/**
	 * 
	 */
	private static final String CREATE_COMMAND = "CreateProfil";

	public CreateProfil(RightsListModel model)
	{
		super(Right.CREATE_PROFIL, "Create");
		mModel = model;
		setActionCommand(CREATE_COMMAND);
		addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		if (CREATE_COMMAND.equals(e.getActionCommand()))
		{
			try
			{
				Collection list = Locator.getUserView().findAllUserActive();
				Collection listProfil = new ArrayList();
				RightsPane view = new RightsPane(listProfil, list);
				GenericEditWindow window = new GenericEditWindow(view, "Create Profile", new ModifyRightBtn(mModel, view));
				window.setHeight(POPUP_HEIGHT);
				window.setWidth(POPUP_WIDTH);
				SuiviProdApp.getApp().getDefaultWindow().getContent().add(window);
			}
			catch (NamingException e1)
			{
				ExceptionMgt.manage(e1);
			}
			catch (FinderException e1)
			{
				ExceptionMgt.manage(e1);
			}
			catch (CreateException e1)
			{
				ExceptionMgt.manage(e1);
			}

		}
	}
}
